home *** CD-ROM | disk | FTP | other *** search
- {The Project should have the following files in it: }
- { µRunTime.lib LSP This is for main Pascal runtime library}
- { Interface.lib LSP This is the Mac trap interfaces}
- { PrintCalls.Lib LSP This is the print routine library interface}
- { MacPrint.p LSP This is the print equates for print calls}
- { InitTheMenus.Pas This initializes the Menus.}
- { Dialog_2 Modal Dialog}
- { Dialog_1 Modal Dialog}
- { HandleTheMenus Handle the menu selections.}
- {Set RUN OPTIONS to use the resource file Draw_Quickly.RSRC }
- { RMaker file to use is Draw_Quickly.R }
- { Draw_Quickly.Pas Main program }
- program Draw_Quickly;
- {Program name: Draw_Quickly.Pas }
- {Function: This is the main module for this program. }
- {History: 10/6/89 Original by Prototyper. }
- { }
- uses
- Dialog_2, Dialog_1, InitTheMenus, Globals, HandleTheMenus, Utilities, DrawMondrian, MenuUtilities;
- var {Main variables}
- myEvent: EventRecord; {Event record for all events}
- doneFlag: boolean; {Exit program flag}
- code: integer; {Determine event type}
- whichWindow: WindowPtr; {See which window for event}
- tempRect, OldRect: Rect; {Rect for dragging}
- mResult: longint; {Menu list and item selected values}
- theMenu, theItem: integer;{Menu list and item selected}
- chCode: integer; {Key code}
- ch: char; {Key pressed in Ascii}
- theInput: TEHandle; {Used in text edit selections}
- myPt: Point; {Temp Point, used in Zoom}
- fullScreen: rect;
- HowWide, HowHigh: Integer;
-
- begin {Start of main body}
-
- MoreMasters; {This reserves space for more handles}
- InitGraf(@thePort); {Quickdraw Init}
- InitFonts; {Font manager init}
- InitWindows; {Window manager init}
- InitMenus; {Menu manager init}
- TEInit; {Text edit init}
- InitDialogs(nil); {Dialog manager}
-
- FlushEvents(everyEvent, 0);{Clear out all events}
- InitCursor; {Make an arrow cursor}
-
- doneFlag := FALSE; {Do not exit program yet}
- NotInDA := true;
-
-
- theInput := nil; {Init to no text edit selection active}
- with ScreenBits.bounds do
- begin
- HowWide := right - left;
- HowHigh := bottom - top;
- end;
- SetRect(fullScreen, 0, 0, (HowWide + 48), (HowHigh + 8));
- SetDrawingRect(fullScreen);
- ShowDrawing;
- D_Dialog_1;
- ShowDrawing;
- Init_My_Menus; {Initialize menu bar}
- WhichShape := Rectangle;
-
-
-
-
- repeat {Start of main event loop}
- if FrontWindow = nil then
- begin
- DisableItem(M_File, 1);
- DisableItem(M_File, 3);
- DisableItem(M_File, 4);
- DisableItem(M_File, 5);
- DisableItem(M_File, 7);
- DisableItem(M_File, 8);
- DisableItem(M_Edit, 1);
- DisableItem(M_Edit, 2);
- DisableItem(M_Edit, 3);
- DisableItem(M_Edit, 4);
- NotInDA := true;
- end;
-
- if (theInput <> nil) then{See if a TE is active}
- TEIdle(theInput); {Blink the cursor if everything is ok}
- SystemTask; {For support of desk accessories}
-
- if GetNextEvent(everyEvent, myEvent) then{If event then...}
- if BitAnd(myEvent.modifiers, $0001) <> 0 then
- begin
- DisableItem(M_File, 1);
- DisableItem(M_File, 3);
- DisableItem(M_File, 4);
- DisableItem(M_File, 5);
- DisableItem(M_File, 7);
- DisableItem(M_File, 8);
- DisableItem(M_Edit, 1);
- DisableItem(M_Edit, 2);
- DisableItem(M_Edit, 3);
- DisableItem(M_Edit, 4);
- NotInDA := true;
- end;
-
-
- begin {Start handling the event}
- code := FindWindow(myEvent.where, whichWindow);{Get which window the event happened in}
- SystemTask;
-
-
- case myEvent.what of{Decide type of event}
- MouseDown: {Mouse button pressed}
- begin {Handle the pressed button}
- SystemTask;
- if (code = inMenuBar) then{See if a menu selection}
- begin {Get the menu selection and handle it}
- SystemTask;
- mResult := MenuSelect(myEvent.Where);{Do menu selection}
- theMenu := HiWord(mResult);{Get the menu list number}
- theItem := LoWord(mResult);{Get the menu list item number}
- Handle_My_Menu(doneFlag, theMenu, theItem, theInput);{Handle the menu}
- end; {End of inMenuBar}
-
- if (code = InDrag) then{See if in a window drag area}
- begin {Do dragging the window}
- tempRect := screenbits.bounds;{Get screen area, l,t,r,b, drag area}
- SetRect(tempRect, tempRect.Left + 10, tempRect.Top + 25, tempRect.Right - 10, tempRect.Bottom - 10);{}
- DragWindow(whichWindow, myEvent.where, tempRect);{Drag the window}
- end; {End of InDrag}
-
- if ((code = inGrow) and (whichWindow <> nil)) then{In a grow area of the window}
- begin {Handle the growing}
- SetPort(whichWindow);{Get ready to draw in this window}
-
- myPt := myEvent.where;{Get mouse position}
- GlobalToLocal(myPt);{Make it relative}
-
- OldRect := WhichWindow^.portRect;{Save the rect before resizing}
-
- with screenbits.bounds do{use the screens size}
- SetRect(tempRect, 15, 15, (right - left), (bottom - top) - 20);{l,t,r,b}
- mResult := GrowWindow(whichWindow, myEvent.where, tempRect);{Grow it}
- SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);{Resize to result}
-
-
- SetPort(whichWindow);{Get ready to draw in this window}
-
- SetRect(tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); {Position for horz scrollbar area}
- EraseRect(tempRect);{Erase old area}
- InvalRect(tempRect);{Flag us to update it}
- SetRect(tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15); {Position for vert scrollbar area}
- EraseRect(tempRect);{Erase old area}
- InvalRect(tempRect);{Flag us to update it}
- DrawGrowIcon(whichWindow);{Draw the grow Icon again}
- end; {End of doing the growing}
-
- if (code = inZoomIn) or (code = inZoomOut) then{Handle Zooming windows}
- begin {}
- if (WhichWindow <> nil) then{See if we have a legal window}
- begin {}
- SetPort(whichWindow);{Get ready to draw in this window}
-
- myPt := myEvent.where;{Get mouse position}
- GlobalToLocal(myPt);{Make it relative}
-
- OldRect := whichWindow^.portRect;{Save the rect before resizing}
-
- if TrackBox(whichWindow, myPt, code) then{Zoom it}
- begin{}
- ZoomWindow(WhichWindow, code, TRUE);{Resize to result}
- SetRect(tempRect, 0, 0, 32000, 32000);{l,t,r,b}
- EraseRect(tempRect);{Make sure we update the whole window effectively}
- InvalRect(tempRect);{Tell ourselves to update, redraw, the window contents}
- end;{}
- end; {}
- end; {}
-
- if (code = inGoAway) then{See if in a window goaway area}
- begin {Handle the goaway button}
- if TrackGoAway(whichWindow, myEvent.where) then{See if mouse released in GoAway box}
- begin {Handle the GoAway}
- end; {End of TrackGoAway}
- end; {End of InGoAway}
-
- if (code = inContent) then{See if in a window}
- begin {Handle the hit inside a window}
- if (whichWindow <> FrontWindow) then{See if already selected or not, in front if selected}
- SelectWindow(whichWindow){Select this window to make it active}
- else {If already in front the already selected}
- begin {Handle the button in the content}
- SetPort(whichWindow);{Get ready to draw in this window}
- end; {End of else}
- end; {End of inContent}
-
- if (code = inSysWindow) then{See if a DA selection}
- SystemClick(myEvent, whichWindow);{Let other programs in}
- SystemTask;
-
- end; {End of MouseDown}
-
- KeyDown, AutoKey:{Handle key inputs}
- begin {Get the key and handle it}
- with myevent do{Check for menu command keys}
- begin {}
- chCode := BitAnd(message, CharCodeMask);{Get character}
- ch := CHR(chCode);{Change to ASCII}
- if (Odd(modifiers div CmdKey)) then{See if Command key is down}
- begin {}
- mResult := MenuKey(ch);{See if menu selection}
- theMenu := HiWord(mResult);{Get the menu list number}
- theItem := LoWord(mResult);{Get the menu item number}
- if (theMenu <> 0) then{See if a list was selected}
- Handle_My_Menu(doneFlag, theMenu, theItem, theInput);{Do the menu selection}
- if ((ch = 'x') or (ch = 'X')) and (theInput <> nil) then{}
- TECut(theInput);{Handle a Cut in a TE area}
- if ((ch = 'c') or (ch = 'C')) and (theInput <> nil) then{}
- TECopy(theInput);{Handle a Copy in a TE area}
- if ((ch = 'v') or (ch = 'V')) and (theInput <> nil) then{}
- TEPaste(theInput);{Handle a Paste in a TE area}
- end {}
- else if (theInput <> nil) then{}
- TEKey(ch, theInput);{}
- end; {}
- end; {End for KeyDown,AutoKey}
-
- UpDateEvt: {Update event for a window}
- begin {Handle the update}
- whichWindow := WindowPtr(myEvent.message);{Get the window the update is for}
- BeginUpdate(whichWindow);{Set the clipping to the update area}
- EndUpdate(whichWindow);{Return to normal clipping area}
- end; {End of UpDateEvt}
-
- DiskEvt: {Disk inserted event}
- begin {Handle a disk event}
- if (HiWord(myevent.message) <> noErr) then{See if a diskette mount error}
- begin {due to unformatted diskette inserted}
- myEvent.where.h := ((screenbits.bounds.Right - screenbits.bounds.Left) div 2) - (304 div 2);{Center horz}
- myEvent.where.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top) div 3) - (104 div 2);{Top 3ed vertically}
- InitCursor;{Make sure it has an arrow cursor}
- chCode := DIBadMount(myEvent.where, myevent.message);{Let the OS handle the diskette}
- end; {}
- end; {End of DiskEvt}
-
- ActivateEvt: {Window activated event}
- begin {Handle the activation}
- whichWindow := WindowPtr(myevent.message);{Get the window to be activated}
- if odd(myEvent.modifiers) then{Make sure it is Activate and not DeActivate}
- begin {Handle the activate}
- SelectWindow(whichWindow);{Activate the window by selecting it}
- end; {End of Activate}
- end; {End of ActivateEvt}
-
- otherwise {Used for debugging, to see what other events are coming in}
- begin {}
- {?? ADDED FOR DEBUGGING, CATCHING OTHER EVENTS}
- {}
- end; {End of otherwise}
-
- end; {End of case}
-
- end; {end of GetNextEvent}
- SystemTask;
- if NotInDA then
- begin
- DrawShapes(WhichShape);
- end;
-
- until doneFlag; {End of the event loop}
-
- end. {End of the program}